<?php

require_once ROOT_DIR.'models/Todo.php';

/**
 * Tries to create a new todo and echos the resulting view.
 * @param string $title
 * @param string $description
 * @param timestamp $targetDate
 * @param float $projectedHours
 */
function newTodo($title, $description, $targetDate, $projectedHours){
	$todo = new Todo($title, $description, $targetDate, $projectedHours, $_SESSION['USER_ID'], 'n');
	if($todo->saveToDB()){
		Todo::linkTodoWithUser($todo->getID(), $todo->getCreatorID(), 'rP');
		$res = new ResultJSON(false, session_id());
		$res->addItem('tID', $todo->getID());
		echo $res->renderView();
	} else {
		$res = new ResultJSON(true, session_id(), ERROR_ACTION_FAILED);
		echo $res->renderView();
	}
}

?>